<template>
  <div>
    <div :key="`bench-home-${facCode}`">
      <ul>
        <li v-for="item in menuList" :key="item.key" :class="[{ active: activeName === item.key }, 'menu-item']" @click="handleChange(item.key)">
          {{ item.name }}
        </li>
      </ul>
      <Bench v-if="activeName === 'bench'" />
      <Overview v-if="activeName === 'overview'" />
    </div>
  </div>
</template>

<script lang="ts" setup>
defineOptions({
  name: "ALL_BENCH"
});
import Overview from "@/views/system/base/boardManage/overview/index.vue";
import { onMounted, onUnmounted, ref } from "vue";
import { useRoute } from "vue-router";
import Bench from "./home/index.vue";

const activeName = ref("bench");
const facCode = ref("");
const menuList = ref([
  {
    key: "bench",
    name: "工作台"
  },
  {
    key: "overview",
    name: "工作看板"
  }
]);
const routes =useRoute()
const handleFacChange = event => {
  if (event.key === "facCode") {
    facCode.value = window.localStorage.getItem("facCode");
  }
};
onMounted(() => {
  // 页面渲染完成，添加监听厂区变化
  window.addEventListener("storage", handleFacChange);
});
onUnmounted(() => {
  // 页面销毁，停止监听
  window.removeEventListener("storage", handleFacChange);
});
const handleChange = val => {
  activeName.value = val;
};
</script>

<style scoped lang="scss">
ul {
  display: flex;
  margin-bottom: 16px;

  li {
    &.menu-item {
      box-sizing: border-box;
      height: 35px;
      padding: 0 20px;
      font-size: 14px;
      font-weight: 500;
      line-height: 35px;
      color: #000;
    }

    &.active {
      background: #e3e8f1;
      border-radius: 4px;
    }

    &:hover {
      cursor: pointer;
    }
  }
}
</style>
